package com.example.controller;

import com.example.bean.ActionBean;
import com.example.dao.ActionDaoImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ActionController {
    @Autowired
    private ActionDaoImpl actionDaoImpl;

    @RequestMapping(value = "api/download_action",method = RequestMethod.GET)
    @ResponseBody
    public String download_action(HttpServletResponse response, @RequestParam("username") String username, @RequestParam("type") String type)
    {
//        String username = "11";
//        String type = "linearlist";
        List<ActionBean> action_list_list = actionDaoImpl.findAllActionByUserNameAndType(username, type);
        if (action_list_list.size()==0) return "";
        ActionBean action_list = action_list_list.get(0);
        System.out.println(action_list.getActionList());
        return action_list.getActionList();
    }

    @PostMapping(value = "api/upload_action")
    @ResponseBody
    public boolean upload_action(HttpServletResponse response, @RequestParam("username") String username, @RequestParam("type") String type,@RequestParam("setUpTime") String set_up_time,@RequestParam("actionList") String action_list)
    {
        ActionBean requestUser = new ActionBean(username,type,set_up_time,action_list);
        boolean flag = actionDaoImpl.addAction(requestUser);
        System.out.println(requestUser);
        return flag;
    }
}
